package com.dyzs.activity;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.app.ExpandableListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.net.ConnectivityManager;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class CommonExpandableListActivity extends ExpandableListActivity {

	
	protected TextView emptyTV;	
	
	protected ProgressDialog proDialog;
	protected void showProgressDialog(String title, String content,
			boolean bl1, boolean bl2) {
		// proDialog.setIcon(icon);//设置标题图标
		// proDialog.setCancelable(true);//是否可以按退回按钮取消
		// proDialog.setIndeterminate(false);//进度条是否不明确
		proDialog = ProgressDialog.show(this, null, content, bl1, bl2);
	}

	protected boolean checkNet() {
		ConnectivityManager cwjManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
		boolean b = cwjManager.getActiveNetworkInfo().isAvailable();
		return b;
	}

	public SimpleAdapter getMenuAdapter(String[] menuNameArray,
			int[] imageResourceArray) {
		ArrayList<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>();
		for (int i = 0; i < menuNameArray.length; i++) {
			HashMap<String, Object> map = new HashMap<String, Object>();
			map.put("itemImage", imageResourceArray[i]);
			map.put("itemText", menuNameArray[i]);
			data.add(map);
		}
		SimpleAdapter simperAdapter = new SimpleAdapter(this, data,
				R.layout.gridview_menu_item, new String[] { "itemImage",
						"itemText" }, new int[] { R.id.gridview_item_iv,
						R.id.gridview_item_tv });
		return simperAdapter;
	}
	
	
	
	public void onException(Context context,final Exception e) {
		((Activity) context).runOnUiThread(new Runnable() {			
			public void run() {
				if(proDialog != null){
					proDialog.dismiss();					
				}
				emptyTV.setText(e.getMessage());				
			}
		});
	}

}
